<?php 
session_start();
include('checkLoggedIn.php');
//include ('find-bus-stop.php');
$page = 'save-alert-options';

include('config.php');
 
$bus = $_POST['bus'];
$street = $_POST['street'];
    
$time_to_leave = $_POST['time_of_bus'];
$time = $time_to_leave;
$day_time = $_POST['day_time'];
if($day_time === "pm"){
	$time_to_leave =  $time_to_leave + 12;
}
//echo "<br>".$time_to_leave ." ". $day_time . "<br>";//= ;
//$time_to_leave = '5';
    
// get all the IDs related to that bus
$busIDs = Routes::getbusIds($bus,$street,$time_to_leave);
    
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta name="viewport" content="width=320, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Save Alert</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="body-wrapper">
<div id="header"><?php include('menu.php');?></div>
	<div id="Content">
		<?php echo 'Search for <b>'. $bus.'</b> leaving at <b>'.$time. $day_time.'</b> <Br/>';?>
		<form action="save.php" method="post">
		<fieldset title="Alert Options">
			<legend>Choose a Bus</legend>
			<div class="row">
			<label for="start-address">Bus stops:
			<input type="hidden" name="bus" value="<?php echo $bus; ?>"/>
			<select  size="1" name="stop_id" >
			<?php foreach($busIDs as $result){
				
				foreach($result['Trips'] as $trip){
					foreach($trip['StopTimes'] as $stop_time){
						
	    			$time = date('g:i a',strtotime($stop_time['arrival_time']));?>
	    			<option value="<?php echo $stop_time['stop_time_id'];?>" selected>
	    			<?php echo $time." - " . ucwords(strtolower($stop_time['Stops']['stop_name']));?>
    			</option>
    			<?php 
    		}
    	}
    }?>
			</select>
			</label></div>
			<div class="row"><label>Send me an alert <select  size="1" name="offset" >
				<?php for ($i = 5; $i<= 60 ; $i += 5){ ?>
				<option><?php echo $i; ?></option>
				<?php } ?>
			</select> mins before arrival</label></div>
			<div class="row">
			<label for="start-address">Choose alert type</label>
			<input type="radio" name="type" value="2" checked="checked">Email</input>
			<input type="radio" name="type" value="1">SMS</input></div>
		</fieldset>
			<div class="row">
				<input type="submit" value="Save" name="save" ></input>
			</div>
		</form>
		<div class="clear"></div>
	</div>
</div>
</body>
</html>